﻿package mortal.game.view.common.tooltip.tooltips
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.text.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.tooltip.*;
    import mortal.game.view.common.tooltip.tooltips.base.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.shopMall.view.*;

    public class ToolTipHalidomEquip extends ToolTipScaleBg implements IToolTipComparableWithUpDownArrow
    {
        private var _txtName:GTextFiled;
        private var _icon:ShopSellItem;
        private var _bmpEquiped:Bitmap;
        private var _txtStrenLv:BitmapNumberText;
        private var _lockIcon:GBitmap;
        private var _txtBind:GTextFiled;
        private var _txtFight:GTextFiled;
        private var _txtSuitType:GTextFiled;
        private var _txtLevel:GTextFiled;
        private var _txtCareer:GTextFiled;
        private var _bmpUpDown:GBitmap;
        private var _txtBasic:GTextFiled;
        private var _txtBasic2:GTextFiled;
        private var _txtBasicLeft:AutoLayoutTextContainer;
        private var _txtBasicRight:AutoLayoutTextContainer;
        private var _addSkillEffect:GTextFiled;
        private var _lineBasic:ScaleBitmap;
        private var _txtDesc:GTextFiled;
        protected var _txtTips:GTextFiled;
        private var _data:ItemData;
        private var _info:ItemEquipInfo;
        private var _combat:int;

        public function ToolTipHalidomEquip()
        {
            this.createChildren();
            paddingBottom = 8;
            paddingLeft = 12;
            paddingRight = 8;
            paddingTop = 8;
            return;
        }// end function

        public function setEquipedData(param1:Object) : void
        {
            return;
        }// end function

        public function set equiped(param1:Boolean) : void
        {
            if (param1)
            {
                if (this._bmpEquiped == null)
                {
                    this._bmpEquiped = UIFactory.bitmap(ImagesConst.EquipedLabel, -10, 18);
                }
                contentContainer2D.addChild(this._bmpEquiped);
            }
            else
            {
                DisplayUtil.removeMe(this._bmpEquiped);
            }
            return;
        }// end function

        override public function set data(param1) : void
        {
            var _loc_2:ItemExInfo = null;
            this._data = param1 as ItemData;
            if (this._data == null)
            {
                return;
            }
            super.data = this._data;
            if (this._data.extInfo)
            {
                this._data.extInfo.strengthen = this._data.itemInfo.itemLevel;
            }
            else
            {
                _loc_2 = new ItemExInfo();
                _loc_2.strengthen = this._data.itemInfo.itemLevel;
                this._data.extInfo = _loc_2;
            }
            this._info = this._data.itemInfo as ItemEquipInfo;
            setBg(ToolTipUtil.getBgNameByColor(this._info.color));
            this.updateTopPart();
            this.updateBasicAttr();
            this.updateSkillEff();
            if (this._data.extInfo != null)
            {
            }
            this.updateLayout();
            _scaleBg.setSize(288, paddingTop + paddingBottom + this._txtTips.y + 20);
            this.updateName();
            return;
        }// end function

        public function setBuyback(param1:int) : void
        {
            var _loc_2:String = null;
            var _loc_3:Boolean = false;
            if (param1 < 0)
            {
                this._txtTips.text = Language.getString(20248);
                this._txtTips.textColor = 3602685;
            }
            else
            {
                _loc_2 = GameDefConfig.instance.getEPrictUnitName(this._data.itemInfo.sellUnit);
                _loc_3 = Cache.instance.role.enoughMoney(this._data.itemInfo.sellUnit, param1);
                if (!_loc_3)
                {
                    this._txtTips.textColor = 16711680;
                }
                else
                {
                    this._txtTips.textColor = 65280;
                }
                this._txtTips.text = Language.getStringByParam(20260, param1.toString() + _loc_2);
            }
            return;
        }// end function

        override public function get width() : Number
        {
            return _scaleBg.width;
        }// end function

        override public function get height() : Number
        {
            return _scaleBg.height;
        }// end function

        private function updateTopPart() : void
        {
            var _loc_1:* = ItemsUtil.isBind(this._data);
            this._icon.itemData = this._data;
            this._icon.isBind = _loc_1;
            this._lockIcon.visible = _loc_1;
            if (_loc_1)
            {
                this._txtBind.textColor = GlobalStyle.colorHongUint;
                this._txtBind.text = Language.getString(20206);
                this._txtBind.x = 100;
            }
            else
            {
                this._txtBind.textColor = GlobalStyle.colorLvUint;
                this._txtBind.text = Language.getString(20205);
                this._txtBind.x = 79;
            }
            this._combat = MountUtil.getMountEquipCombatByItemData(this._data);
            this._txtFight.text = Language.getStringByParam(20800, this._combat.toString());
            this._bmpUpDown.x = this._txtFight.x + this._txtFight.width + 8 - 50;
            this._bmpUpDown.visible = false;
            var _loc_2:* = Language.getString(20801);
            this._txtSuitType.text = _loc_2;
            this._txtLevel.text = Language.getString(30011) + "：" + this._info.level.toString();
            var _loc_3:* = this.getLimitDec(this._info.level);
            this._txtCareer.htmlText = this.getLimitDec(this._info.level);
            this._txtDesc.height = 200;
            this._txtDesc.htmlText = this._info.alyDesc() ? (this._info.alyDesc()) : (Language.getString(20784));
            this._txtDesc.height = this._txtDesc.textHeight + 8;
            return;
        }// end function

        private function getLimitDec(param1:int) : String
        {
            return "";
        }// end function

        private function updateBasicAttr() : void
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:AttributeData = null;
            var _loc_1:* = AttributeUtil.getEquipmentBasicAttrs(this._data.itemInfo as ItemEquipInfo, this._data.addPercent);
            var _loc_2:* = this._txtBasicLeft.numChildren;
            var _loc_3:* = _loc_1.length - _loc_2;
            if (_loc_3 > 0)
            {
                _loc_5 = 0;
                while (_loc_5 < _loc_3)
                {
                    
                    this._txtBasicLeft.addNewText(120);
                    this._txtBasicRight.addNewText(120, "", 12, GlobalStyle.colorLvUint);
                    _loc_5++;
                }
            }
            else if (_loc_3 < 0)
            {
                this._txtBasicLeft.split(_loc_1.length);
                this._txtBasicRight.split(_loc_1.length);
            }
            _loc_5 = 0;
            while (_loc_5 < _loc_1.length)
            {
                
                _loc_6 = _loc_1[_loc_5];
                this._txtBasicLeft.setText(_loc_5, _loc_6.name + " : " + _loc_6.value);
                _loc_5++;
            }
            return;
        }// end function

        private function updateSkillEff() : void
        {
            var _loc_1:Array = null;
            var _loc_2:String = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:TSkill = null;
            if (this._data.itemInfo.skill == null || this._data.itemInfo.skill == "")
            {
                this._addSkillEffect.visible = false;
            }
            else
            {
                this._addSkillEffect.visible = true;
                _loc_1 = this._data.itemInfo.skill.split("#");
                _loc_2 = "";
                _loc_3 = 0;
                while (_loc_3 < _loc_1.length)
                {
                    
                    _loc_4 = int(_loc_1[_loc_3]);
                    _loc_5 = SkillConfig.instance.getInfoById(_loc_4);
                    if (_loc_3 != 0)
                    {
                        _loc_2 = _loc_2 + ("\n" + _loc_5.skillDescription);
                    }
                    else
                    {
                        _loc_2 = _loc_5.skillDescription;
                    }
                    _loc_3++;
                }
                this._addSkillEffect.htmlText = HTMLUtil.addColor(_loc_2, "#ffc293");
            }
            this._addSkillEffect.visible = false;
            return;
        }// end function

        private function updateName() : void
        {
            this._txtName.width = _scaleBg.width;
            var _loc_1:* = ColorConfig.instance.getItemColorString(this._data.itemInfo.color);
            var _loc_2:* = HTMLUtil.addColor(this._data.itemInfo.name, _loc_1);
            this._txtName.htmlText = _loc_2;
            this._txtName.x = -6;
            return;
        }// end function

        private function createChildren() : void
        {
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = TextFormatAlign.CENTER;
            _loc_1.size = 14;
            _loc_1.bold = true;
            this._txtName = UIFactory.gTextField("", -6, 0, 220, 25, this, _loc_1);
            this._icon = UICompomentPool.getUICompoment(ShopSellItem);
            this._icon.x = 0;
            this._icon.y = 26;
            this._icon.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            this._icon.createDisposedChildren();
            this.addChild(this._icon);
            this._icon.isShowLock = false;
            _loc_1 = GlobalStyle.embedNumberTf;
            _loc_1.color = GlobalStyle.colorHuangUint;
            _loc_1.align = TextFormatAlign.RIGHT;
            this._txtStrenLv = UIFactory.bitmapNumberText(this._icon.x, this._icon.y + 50, "EquipmentTipsNumber.png", 16, 16, -5, this);
            this._lockIcon = UIFactory.bitmap(ImagesConst.LockIcon, 81, 34, contentContainer2D);
            this._txtBind = UIFactory.gTextField("", 100, 30, 100, 20, contentContainer2D);
            this._txtFight = UIFactory.gTextField("", 158, 30, 120, 20, contentContainer2D);
            this._txtFight.textColor = 15911263;
            this._txtSuitType = UIFactory.gTextField("", 79, 52, 100, 20, contentContainer2D);
            this._txtLevel = UIFactory.gTextField("", 158, 52, 100, 20, contentContainer2D);
            this._txtCareer = UIFactory.gTextField("", 79, 74, 200, 20, contentContainer2D);
            this._bmpUpDown = UIFactory.gBitmap(null, 0, 78 - 46, contentContainer2D);
            this._txtBasic = UIFactory.gTextField(Language.getString(20210), 0, 114, 100, 20, contentContainer2D);
            this._txtBasic.textColor = GlobalStyle.colorChenUint;
            this._txtBasic2 = UIFactory.gTextField(Language.getString(20786), 79, 114, 160, 20, contentContainer2D);
            this._txtBasic2.visible = false;
            this._txtBasicLeft = new AutoLayoutTextContainer();
            this._txtBasicLeft.x = this._txtBasic.x;
            this._txtBasicLeft.y = this._txtBasic.y + 22;
            this._txtBasicLeft.verticalGap = -7;
            this.addChild(this._txtBasicLeft);
            this._txtBasicRight = new AutoLayoutTextContainer();
            this._txtBasicRight.x = this._txtBasic2.x + 3;
            this._txtBasicRight.y = this._txtBasicLeft.y;
            this._txtBasicRight.verticalGap = -7;
            this.addChild(this._txtBasicRight);
            this._addSkillEffect = UIFactory.gTextField("TextField", this._txtBasic.x, 245, 200, 80, this, GlobalStyle.textFormatAnjin);
            this._addSkillEffect.multiline = true;
            this._addSkillEffect.wordWrap = true;
            this._lineBasic = UIFactory.bg(0, 186, 256, 2, contentContainer2D, ImagesConst.SplitLine);
            this._txtDesc = UIFactory.gTextField("", 0, this._lineBasic.y + 4, 270, 120, contentContainer2D);
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            this._txtTips = UIFactory.gTextField(Language.getString(20248), 0, this._txtDesc.y + 60, 280, 20, contentContainer2D);
            this._txtTips.textColor = 3602685;
            return;
        }// end function

        private function updateLayout() : void
        {
            var _loc_1:* = this._txtBasic.y + 25;
            this._txtBasicRight.y = this._txtBasic.y + 25;
            this._txtBasicLeft.y = _loc_1;
            if (this._addSkillEffect.visible)
            {
                this._addSkillEffect.y = this._txtBasicLeft.y + this._txtBasicLeft.height - 5;
                this._lineBasic.y = this._addSkillEffect.y + this._addSkillEffect.textHeight + 5;
            }
            else
            {
                this._lineBasic.y = this._txtBasicLeft.y + this._txtBasicLeft.height;
            }
            this._txtDesc.y = this._lineBasic.y + 5;
            this._txtTips.y = this._txtDesc.y + this._txtDesc.height;
            return;
        }// end function

        public function updateCombatUpDown(param1:int) : void
        {
            this._bmpUpDown.visible = true;
            if (this._combat > param1)
            {
                this._bmpUpDown.bitmapData = GlobalClass.getBitmapData(ImagesConst.ToolTipUpArrow);
            }
            else if (this._combat == param1)
            {
                this._bmpUpDown.visible = false;
            }
            else
            {
                this._bmpUpDown.bitmapData = GlobalClass.getBitmapData(ImagesConst.ToolTipDownArrow);
            }
            return;
        }// end function

        public function getMyCombat() : int
        {
            return this._combat;
        }// end function

    }
}
